Various fixes against the v25 branch.#13
Conversation
The code was previously passing a pointer to the handle to c code. The pointer could be garbage collected before being used.
… that can be passed as an unsafe.Pointer or as a void* in c.
|
Fixed the handle issue by introducing our own |
|
Note: i've now forked the repository and added more things on the main branch, that you might not want to have upstream. This includes improved garbage collection of wgpu resources, makeing calls to |
|
It would be really nice to hear from the maintainers, if there are plans to either merge these improvements or cherry pick certain things out of it. |
|
@kkoreilly and I will have a chance to discuss this soon and will post an update within a couple of weeks hopefully! |
kkoreilly
left a comment
There was a problem hiding this comment.
@oliverbestmann Thanks for these changes! Apologies for the very delayed response, I've been quite busy.
Overall things look good, I just have a couple comments below.
| (queue, buf, offset, addr, x, n) => { | ||
| const mem = wasm.instance.exports.mem.buffer; | ||
| const data = new Uint8ClampedArray(mem, addr, n); | ||
| return queue.writeBuffer(buf, offset, data, x, n); |
There was a problem hiding this comment.
I'm curious why this change is necessary as opposed to the previous jsx.BytesToJS approach. Does this solve the occasional crashing that occurred previously, or is there another motivation?
There was a problem hiding this comment.
Performance iirc. It was precisely jumping to is and back a billion of times. Also yes, it crashed here previously, that got better now. One more thing: As you only take the uintptr of the Adress, the gc can theoretically dealloc the slice before it is used at the end of the function.
| ) | ||
|
|
||
| require ( | ||
| cogentcore.org/core v0.3.12 // indirect |
There was a problem hiding this comment.
Why is core now an indirect dependency?
There was a problem hiding this comment.
I thought I got rid of that too. I would need to check for what that is used ;)
|
@oliverbestmann The changes on your main branch look good overall, and if you are interested in filing separate PRs for them, that would be awesome (no worries if not). For the binary size limit, I wonder whether it might be easier to use different modules within the same branch rather than in separate branches? You could have separate Could you briefly explain how you implemented the garbage collection and whether there are any major negative side effects of that? Thanks for all of your contributions, and apologies again for our unresponsiveness, I've been very busy but should hopefully have more time to respond going forward. |
|
Regarding the binary size limit: I am not sure if I tried that. I think the size limit is per shallow clone of the repository, not the module subdirectory. Garbage collection: it is really just registering finalizers like here: https://github.com/oliverbestmann/webgpu/blob/main/wgpu/wgpu.go#L122 Special care needs to be taken when addRef is used, see a few lines above. The release method was made idempotent, so it can be called multiple times without crashing: https://github.com/oliverbestmann/webgpu/blob/main/wgpu/gen_types.go#L266 I am currently also very busy due to $work and family, so I probably won't create multiple pull requests. I am sorry! |
|
One consideration for timing of update of underlying libraries, assuming there remains some kind of cost to updating the libraries more frequently (hopefully @kkoreilly 's proposed solution might avoid that??) is the possible resolution of this issue: gfx-rs/wgpu#8119 -- this would probably be the single biggest issue fix for my usage. |
|
@rcoreilly What is the timeline on gfx-rs/wgpu#8119? If it will be resolved soon, we can wait until then to finish this up. Otherwise we can work on merging this sooner (and I will experiment with the different approach for the binary libraries). |
|
@kkoreilly IDK about the timing -- no evidence of progress or stated focus on this, so presumably not too soon. I think it would make sense for you to experiment with the approach for the binaries at this point. |
|
https://github.com/oliverbestmann/webgpu is now updated to |
Lets rephrase that, I've updated to wgpu-native v29. |
|
@oliverbestmann I just tried to see if I could make a PR from your current main branch, and github says it is not possible because they have "entirely different commit histories". In any case, it seems like you are continuing to actively update things, and I think at this point it would probably make sense for this repo to just point to yours as the definitive version, rather than trying to keep two copies in sync. @kkoreilly does this sound reasonable to you? I will experiment with using yours now in cogentcore, and will probably file a PR for using glfw 3.4 -- would you be OK updating to that? |
|
Yea of course. I can probably do the glfw update myself later today or tomorrow too. Otherwise feel free to report whatever issue you might have, I am happy to fix those asap. |
|
I've updated to 3.4. There is a small issue if you want to use both x11 and wayland without build tags. |
|
@oliverbestmann you don't have issues or discussions enabled on your repo page! I am getting a nearly-100% reliable crash on Mac (Macbook Pro 2023, M3) in running the examples, which first appears in v1.30.0 (a254e95) when you updated to v29.0.0.0 Very occasionally it will run, but mostly it crashes, with the stack shown below. If I use 337844f, examples run reliably. This looks like a clear upstream, mac-specific issue. Not specific to glfw 3.4, but it may interact with glfw generically somehow -- seems like some kind of timing issue given the randomness of the crash. I'll look into the upstream system to see if I can reproduce anything there. |
|
Enabled the issues tab on the repo. fmt.Println("Next Texture is valid:", nextTexture.IsValid())
if !nextTexture.IsValid() {
return nil
}I'll see what I can do, maybe I can add a workaround. |
|
Done. I now correctly expose the status of the returned SurfaceTexture. You now need to handle this status and, for example, skip rendering if the surface is occluded. See the cube example for reference. |
|
Thanks for the fix -- I was trying something similar in a fork but hoping to somehow avoid having every single program anyone ever writes to include that logic.. I don't see how to encapsulate it anywhere sensible though. Here's the actual issue with links to all associated issues and PRs: gfx-rs/wgpu#9430 |
I can split the PR up into multiple small onces, but as the v25 PR is already one single big PR, i just went with another big one ;)
cgo.HandleDesiredMaximumFrameLatencyinSurfaceConfigurationQueue.WriteBufferandQueue.WriteTextureVertexFormat.Size()Texturefor js.